placesview: vertically align path labels
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 29 Oct 2015 12:14:57 +0000 (10:14 -0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Fri, 30 Oct 2015 13:35:43 +0000 (11:35 -0200)
The current situation is somewhat sad, with the path
label totally misaligned throughout the rows.

This is fixed by using a size group for the path labels,
so they all have the same allocated size (with the max
of 15 chars). Also, instead of hiding the eject button,
set it child-invisible, so it is hidden and yet it's size
is allocated by GtkBox.

https://bugzilla.gnome.org/show_bug.cgi?id=757303

gtk/gtkplacesview.c
gtk/gtkplacesviewrow.c
gtk/gtkplacesviewrowprivate.h
gtk/ui/gtkplacesviewrow.ui

index 7c70e98085cd0c0efea16b049505474bb280a02f..77dd938d92a3b88b7d2ae5057da47c078e1b557b 100644 (file)
@@ -72,6 +72,8 @@ struct _GtkPlacesViewPrivate
   GtkWidget                     *network_placeholder;
   GtkWidget                     *network_placeholder_label;
 
+  GtkSizeGroup                  *path_size_group;
+
   GtkEntryCompletion            *address_entry_completion;
   GtkListStore                  *completion_store;
 
@@ -406,6 +408,7 @@ gtk_places_view_finalize (GObject *object)
   g_clear_object (&priv->volume_monitor);
   g_clear_object (&priv->cancellable);
   g_clear_object (&priv->networks_fetching_cancellable);
+  g_clear_object (&priv->path_size_group);
 
   G_OBJECT_CLASS (gtk_places_view_parent_class)->finalize (object);
 }
@@ -674,6 +677,8 @@ insert_row (GtkPlacesView *view,
                     G_CALLBACK (on_eject_button_clicked),
                     row);
 
+  gtk_places_view_row_set_path_size_group (GTK_PLACES_VIEW_ROW (row), priv->path_size_group);
+
   gtk_container_add (GTK_CONTAINER (priv->listbox), row);
 }
 
@@ -2254,6 +2259,7 @@ gtk_places_view_init (GtkPlacesView *self)
 
   priv->volume_monitor = g_volume_monitor_get ();
   priv->open_flags = GTK_PLACES_OPEN_NORMAL;
+  priv->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
   gtk_widget_init_template (GTK_WIDGET (self));
 }
index 8c1d1cb1278bc4a666c4b8fba908bc0bcad598e3..3466053e4f20a56a0e5fd54298e57736f6d44b4b 100644 (file)
@@ -150,7 +150,15 @@ gtk_places_view_row_set_property (GObject      *object,
 
     case PROP_MOUNT:
       g_set_object (&self->mount, g_value_get_object (value));
-      gtk_widget_set_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
+
+      /*
+       * When we hide the eject button, no size is allocated for it. Since
+       * we want to have alignment between rows, it needs an empty space
+       * when the eject button is not available. So, call then
+       * gtk_widget_set_child_visible(), which makes the button allocate the
+       * size but it stays hidden when needed.
+       */
+      gtk_widget_set_child_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
       break;
 
     case PROP_FILE:
@@ -323,3 +331,11 @@ gtk_places_view_row_set_is_network (GtkPlacesViewRow *row,
       gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? _("Disconnect") : _("Unmount"));
     }
 }
+
+void
+gtk_places_view_row_set_path_size_group (GtkPlacesViewRow *row,
+                                         GtkSizeGroup     *group)
+{
+  if (group)
+    gtk_size_group_add_widget (group, GTK_WIDGET (row->path_label));
+}
index 3c46d5d9a5d01011c3f168febbc440e8760eb792..2d5da7e5fb676becee0c7860d0009fb38e088030 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include "gtkwidget.h"
+#include "gtksizegroup.h"
 #include "gtklistbox.h"
 
 G_BEGIN_DECLS
@@ -53,6 +54,9 @@ gboolean           gtk_places_view_row_get_is_network            (GtkPlacesViewR
 void               gtk_places_view_row_set_is_network            (GtkPlacesViewRow   *row,
                                                                   gboolean            is_network);
 
+void               gtk_places_view_row_set_path_size_group       (GtkPlacesViewRow   *row,
+                                                                  GtkSizeGroup       *group);
+
 G_END_DECLS
 
 #endif /* GTK_PLACES_VIEW_ROW_H */
index 2d06d0d872462d11a0f4a2a51056e3086ffddf03..9ace5b93004f133832e00496a2d1ffe59882d138 100644 (file)
@@ -40,8 +40,7 @@
                 <property name="visible">1</property>
                 <property name="justify">right</property>
                 <property name="ellipsize">middle</property>
-                <property name="xalign">1</property>
-                <property name="width_chars">15</property>
+                <property name="xalign">0</property>
                 <property name="max_width_chars">15</property>
                 <style>
                   <class name="dim-label"/>
@@ -53,6 +52,7 @@
             </child>
             <child>
               <object class="GtkButton" id="eject_button">
+                <property name="visible">True</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
                 <property name="tooltip-text" translatable="yes">Unmount</property>